package com.example.yemiantiaozhuan;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.io.IOException;

public class AActivity extends Activity {
    private Button nqy;
    private Button sqg;
    private Button yjf;
    private Button marp;
    private TextView tv;
   // private Handler handler ;
    private  String st="    上饶三清山，   鬼斧神工造奇峰";
    protected static final int UI = 100;
    private char[] charArrays;
    private String len = "";
private MediaPlayer player;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.layout);
        nqy = (Button) findViewById(R.id.nqy);
        sqg = (Button) findViewById(R.id.sqg);
        yjf = (Button) findViewById(R.id.yjf);
        marp = (Button) findViewById(R.id.marp);
        tv = (TextView) findViewById(R.id.tv);

playAudio();




        new Thread(){
            public void run() {
                try {
                    charArrays = st.toCharArray();
                    for (int i = 0; i < charArrays.length; i++) {
                        sleep(600);
                        len = charArrays[i]+"";

//                        Message mess=new Message();
//                        mess.what=0x12;
                        handler.sendEmptyMessage(UI);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            };
        }.start();




        nqy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();
                intent.setClass(AActivity.this, BActivity.class);
                startActivity(intent);
                 finish();
            }

        });
        sqg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(AActivity.this, CActivity.class);
                startActivity(intent);
                finish();
            }
        });
        yjf.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(AActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
          }
        });
         marp.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setClass(AActivity.this, DActivity.class);
        startActivity(intent);
        finish();
    }
});
    }

   Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            switch (msg.what) {
                case UI:
                    tv.append(len);
                    break;

                default:
                    break;
            }
        }


    };

    private void playAudio() {
        try {
            player = MediaPlayer.create(this, R.raw.music);
            player.start();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  catch (Exception e) {
            e.printStackTrace();
        }

    }
    protected void onDestroy() {
        super.onDestroy();
       if (player!=null){
           player.release();
           player=null;
       }
    }



}
